package com.chixing.service.impl;

import com.chixing.mapper.CustomerMapper;
import com.chixing.mapper.HotelInfoMapper;
import com.chixing.pojo.Customer;
import com.chixing.pojo.CustomerExample;
import com.chixing.pojo.HotelInfo;
import com.chixing.pojo.HotelInfoExample;
import com.chixing.service.CustomerService;
import com.chixing.util.ServerResponse;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;

import javax.annotation.Resource;
import java.util.List;
@Service
public class CustomerServiceImpl implements CustomerService {

    @Autowired
    public  CustomerMapper customerMapper;




    @Override
    public Customer getById(int id) {
        return null;
    }

    @Override
    public boolean save(Customer customer) {
        int insert = customerMapper.insert(customer);
        if (insert>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean update(Customer customer) {
        return false;
    }

    @Override
    public boolean delete(Integer id) {
        return false;
    }

    @Override
    public boolean getByOthers(String custName, String custPwd) {
        return false;
    }

    @Override
    public ServerResponse getByTelno(Long custTelno) {
        Customer customer=null;
       CustomerExample example =  new CustomerExample();
       example.createCriteria().andCustTelnoEqualTo(custTelno);
        List<Customer> customerList = customerMapper.selectByExample(example);
        if (customerList!=null&&customerList.size()>=1){
            customer = customerList.get(0);
            return ServerResponse.getDataSuccess(customer);
        }
        return ServerResponse.getDataFailue(null);
    }

    @Override
    public ServerResponse getPwdByCustNo(Long custNo) {
        Customer customer = null;
        CustomerExample example =  new CustomerExample();
        example.createCriteria().andCustNoEqualTo(custNo);
        List<Customer> customerList = customerMapper.selectByExample(example);
        if (customerList!=null&&customerList.size()>=1){
            customer = customerList.get(0);
            String custPwd = customer.getCustPwd();
            return ServerResponse.getDataSuccess(custPwd);
        }
        return ServerResponse.getDataFailue(null);
    }

    @Override
    public ServerResponse getByCustNo(Long custNo) {
        Customer customer=null;
        CustomerExample example =  new CustomerExample();
        example.createCriteria().andCustNoEqualTo(custNo);
        List<Customer> customerList = customerMapper.selectByExample(example);
        if (customerList!=null&&customerList.size()>=1){
            customer = customerList.get(0);
            return ServerResponse.getDataSuccess(customer);
        }
        return ServerResponse.getDataFailue(null);
    }

    @Override
    public List<Customer> getAll() {
        return null;
    }

    @Override
    public PageInfo<Customer> getByPage(Integer pageNum) {
        return null;
    }
}
